<template>
	<el-main class="bg edit_wrap">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
			<el-col v-if="user_group === '管理员' || $check_field('get','dormitory_building_id') || $check_field('add','dormitory_building_id') || $check_field('set','dormitory_building_id')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="宿舍楼" prop="dormitory_building_id">
					<el-input id="dormitory_building_id" v-model="form['dormitory_building_id']" placeholder="请输入宿舍楼ID"
							  v-if="user_group === '管理员' || (form['sanitary_inspection_id'] && $check_field('set','dormitory_building_id')) || (!form['sanitary_inspection_id'] && $check_field('add','dormitory_building_id'))" :disabled="disabledObj['dormitory_building_id_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','dormitory_building_id')">{{form['dormitory_building_id']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','dormitory_id') || $check_field('add','dormitory_id') || $check_field('set','dormitory_id')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="宿舍" prop="dormitory_id">
					<el-input id="dormitory_id" v-model="form['dormitory_id']" placeholder="请输入宿舍ID"
							  v-if="user_group === '管理员' || (form['sanitary_inspection_id'] && $check_field('set','dormitory_id')) || (!form['sanitary_inspection_id'] && $check_field('add','dormitory_id'))" :disabled="disabledObj['dormitory_id_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','dormitory_id')">{{form['dormitory_id']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','audit_date') || $check_field('add','audit_date') || $check_field('set','audit_date')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="审核日期" prop="audit_date">
					<el-date-picker :disabled="disabledObj['audit_date_isDisabled']" v-if="user_group === '管理员' || (form['sanitary_inspection_id'] && $check_field('set','audit_date')) || (!form['sanitary_inspection_id'] && $check_field('add','audit_date'))" id="audit_date"
						v-model="form['audit_date']" type="date" placeholder="选择日期">
					</el-date-picker>
					<div v-else-if="$check_field('get','audit_date')">{{form['audit_date']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','the_ground_is_clean_and_tidy') || $check_field('add','the_ground_is_clean_and_tidy') || $check_field('set','the_ground_is_clean_and_tidy')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="地面整洁" prop="the_ground_is_clean_and_tidy">
					<el-input id="the_ground_is_clean_and_tidy" v-model="form['the_ground_is_clean_and_tidy']" placeholder="请输入地面整洁"
							  v-if="user_group === '管理员' || (form['sanitary_inspection_id'] && $check_field('set','the_ground_is_clean_and_tidy')) || (!form['sanitary_inspection_id'] && $check_field('add','the_ground_is_clean_and_tidy'))" :disabled="disabledObj['the_ground_is_clean_and_tidy_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','the_ground_is_clean_and_tidy')">{{form['the_ground_is_clean_and_tidy']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','toilet_sanitation') || $check_field('add','toilet_sanitation') || $check_field('set','toilet_sanitation')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="厕所卫生" prop="toilet_sanitation">
					<el-input id="toilet_sanitation" v-model="form['toilet_sanitation']" placeholder="请输入厕所卫生"
							  v-if="user_group === '管理员' || (form['sanitary_inspection_id'] && $check_field('set','toilet_sanitation')) || (!form['sanitary_inspection_id'] && $check_field('add','toilet_sanitation'))" :disabled="disabledObj['toilet_sanitation_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','toilet_sanitation')">{{form['toilet_sanitation']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','window_hygiene') || $check_field('add','window_hygiene') || $check_field('set','window_hygiene')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="窗户卫生" prop="window_hygiene">
					<el-input id="window_hygiene" v-model="form['window_hygiene']" placeholder="请输入窗户卫生"
							  v-if="user_group === '管理员' || (form['sanitary_inspection_id'] && $check_field('set','window_hygiene')) || (!form['sanitary_inspection_id'] && $check_field('add','window_hygiene'))" :disabled="disabledObj['window_hygiene_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','window_hygiene')">{{form['window_hygiene']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','odor_and_sundries') || $check_field('add','odor_and_sundries') || $check_field('set','odor_and_sundries')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="异味杂物" prop="odor_and_sundries">
					<el-input id="odor_and_sundries" v-model="form['odor_and_sundries']" placeholder="请输入异味杂物"
							  v-if="user_group === '管理员' || (form['sanitary_inspection_id'] && $check_field('set','odor_and_sundries')) || (!form['sanitary_inspection_id'] && $check_field('add','odor_and_sundries'))" :disabled="disabledObj['odor_and_sundries_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','odor_and_sundries')">{{form['odor_and_sundries']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','clean_and_tidy_articles') || $check_field('add','clean_and_tidy_articles') || $check_field('set','clean_and_tidy_articles')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="物品整洁" prop="clean_and_tidy_articles">
					<el-input id="clean_and_tidy_articles" v-model="form['clean_and_tidy_articles']" placeholder="请输入物品整洁"
							  v-if="user_group === '管理员' || (form['sanitary_inspection_id'] && $check_field('set','clean_and_tidy_articles')) || (!form['sanitary_inspection_id'] && $check_field('add','clean_and_tidy_articles'))" :disabled="disabledObj['clean_and_tidy_articles_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','clean_and_tidy_articles')">{{form['clean_and_tidy_articles']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','comprehensive_score') || $check_field('add','comprehensive_score') || $check_field('set','comprehensive_score')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="综合评分" prop="comprehensive_score">
					<el-input id="comprehensive_score" v-model="form['comprehensive_score']" placeholder="请输入综合评分"
							  v-if="user_group === '管理员' || (form['sanitary_inspection_id'] && $check_field('set','comprehensive_score')) || (!form['sanitary_inspection_id'] && $check_field('add','comprehensive_score'))" :disabled="disabledObj['comprehensive_score_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','comprehensive_score')">{{form['comprehensive_score']}}</div>
				</el-form-item>
			</el-col>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item>
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";

	export default {
		mixins: [mixin],
		data() {
			return {
				field: "sanitary_inspection_id",
				url_add: "~/api/sanitary_inspection/add?",
				url_set: "~/api/sanitary_inspection/set?",
				url_get_obj: "~/api/sanitary_inspection/get_obj?",
				url_upload: "~/api/sanitary_inspection/upload?",

				query: {
					"sanitary_inspection_id": 0,
				},

				form: {
					"dormitory_building_id":'', // 宿舍楼ID
					"dormitory_id":'', // 宿舍ID
					"audit_date":'', // 审核日期
					"the_ground_is_clean_and_tidy":'', // 地面整洁
					"toilet_sanitation":'', // 厕所卫生
					"window_hygiene":'', // 窗户卫生
					"odor_and_sundries":'', // 异味杂物
					"clean_and_tidy_articles":'', // 物品整洁
					"comprehensive_score":'', // 综合评分
					"sanitary_inspection_id": 0, // ID

				},
				disabledObj:{
					"dormitory_building_id_isDisabled": false,
					"dormitory_id_isDisabled": false,
					"audit_date_isDisabled": false,
					"the_ground_is_clean_and_tidy_isDisabled": false,
					"toilet_sanitation_isDisabled": false,
					"window_hygiene_isDisabled": false,
					"odor_and_sundries_isDisabled": false,
					"clean_and_tidy_articles_isDisabled": false,
					"comprehensive_score_isDisabled": false,
				},
			}
		},
		methods: {

			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
				if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
							}
						})
					})
				}
        if (this.form["audit_date"].indexOf("-")===-1){
          this.form["audit_date"] = this.$toTime(parseInt(this.form["audit_date"]),"yyyy-MM-dd")
        }
				$.db.del("form");
				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){
				if(parseInt(this.form["audit_date"]) > 9999){
					this.form["audit_date"] = this.$toTime(parseInt(this.form["audit_date"]),"yyyy-MM-dd")
				}
			},

			is_view(){
				var bl = this.user_group == "管理员";

				if(!bl){
					bl = this.$check_action('/sanitary_inspection/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/sanitary_inspection/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/sanitary_inspection/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/sanitary_inspection/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/sanitary_inspection/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
		},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}
</style>
